package com.example.icedcap.topeka_fake.helper;

import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;

/**
 * Author: doushuqi
 * Date: 15/7/14
 * Time: 下午1:33
 * Email: shuqi.dou@singuloid.com
 */
public class JsonHelper {

    private static final String TAG = JsonHelper.class.getSimpleName();

    public JsonHelper() {
        //no instance
    }

    public static String[] jsonArrayToStringArray(String json) {
        try {
            JSONArray jsonArray = new JSONArray(json);
            String[] stringArray = new String[jsonArray.length()];
            for (int i = 0; i < jsonArray.length(); i++) {
                stringArray[i] = jsonArray.getString(i);
            }
            return stringArray;
        } catch (JSONException e) {
            Log.e(TAG, "jsonArrayToStringArray", e);
        }
        return new String[0];
    }

    public static int[] jsonArrayToIntArray(String json) {
        try {
            JSONArray jsonArray = new JSONArray(json);
            int[] intArray = new int[jsonArray.length()];
            for (int i = 0; i < jsonArray.length(); i++) {
                intArray[i] = jsonArray.getInt(i);
            }
            return intArray;
        } catch (JSONException e) {
            Log.e(TAG, "jsonArrayToIntArray", e);
        }

        return new int[0];
    }
}
